<?php 
class UserAction extends Action{
    private $table_name = "User";
    function index(){
	    import('ORG.Util.Page');					 
	    $count=M($this->table_name)->count();		 
	    $Page = new Page($count,C('PAGESIZE'));					 
	    $show= $Page->show();	                    
	    $list = M($this->table_name);
	    if(isset($_POST['keywords'])){
        	$map['username'] = array('like','%'.$_POST['keywords'].'%');
        	 $list =$list->where($map);
        }

	    $list=$list->order("uid DESC")->limit($Page->firstRow.','.$Page->listRows)->select();	                   	                      
	    $this->assign("list",$list);						  
	    $this->assign("page",$show);                          
	    $this->display();
	}
	function edit(){		 	
		$uid = empty($_GET['uid'])?exit():$_GET['uid'];                  
		if(isset($_POST['submit'])){                  	
			if($_POST['usertype']>1){                  		
				$data['vip']=1;
			}else{                  		                  		
				$data['vip']=0; }        
			$data['usertype']=$_POST['usertype']; 
			if($_POST['password']){
				$data['password']=md5($_POST['password']);
			}                 	
			M('User')->where("uid=".$uid)->save($data);                  	
			M('company')->where("uid=".$uid)->setField('vip',$data['vip']);
			$this->success("修改用户信息成功",U('index'));                  
			
		}else{                  	
				$this->li =M('User')->where("uid=".$uid)->find();                  	
				$this->display();
		}
	}		 		
	function status(){		   
		$uid = empty($_GET['uid'])?exit():$_GET['uid'];		   
		$type = $_GET['type'];		   
		M('User')->where("uid=".$uid)->setField("status", $type);			   
		$this->success("修改状态成功！");			
	}  
	
	function del(){						
		$qstr = $_GET['qstr'];	     		  		  	
		$data=M('User');  		  	
		$data2=M('Company');  		  			
		if(isset($qstr)){			   
			$arr=explode(",",$qstr);			   
			foreach($arr as $val){			     
				$data->where("uid=$val")->delete();			     
				$data2->where("uid=$val")->delete();
			}
			$this->success("删除成功！",U('index'));						
		}else{		
			$uid = empty($_GET['uid'])?exit():$_GET['uid'];			  			  
			M('User')->where("uid=".$uid)->delete();			  
			M('company')->where("uid=".$uid)->delete();			  
			M('company_feedback')->where("company_id=".$uid)->delete();			  
			M('company_news')->where("uid=".$uid)->delete();			  
			M('company_rongyu')->where("uid=".$uid)->delete();			  
			M('zhaopin')->where('uid='.$uid)->delete();			  			  
			$this->success("删除成功！");			
		}		
	}

	function chongzhi(){
	    $uid = I('get.uid');
	    if(isset($_POST['submit'])){
	        $number = I('post.number');
            M('User')->where(array('uid'=>$uid))->setField("price",$number);
            $this->success("充值成功！",U('index'));

        }else{
	        $this->info = M('User')->where(array('uid'=>$uid))->find();
            $this->display();
        }

    }
}
?>